package qmm.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import qmm.entity.User;
import qmm.util.JdbcUtil;

@WebServlet("/EditPhoneServlet")
public class EditPhoneServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public EditPhoneServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		String phone = request.getParameter("phone");
		String sql = "update t_user set phone='"+phone+"' where id="+user.getId();
		System.out.println(sql);
		int n = JdbcUtil.update(sql);
		if(n>0){
			user.setPhone(phone);
			session.setAttribute("user", user);//ˢsession
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import qmm.entity.User;
import qmm.util.JdbcUtil;

@WebServlet("/EditNickNameServlet")
public class EditNickNameServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public EditNickNameServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("user");
		String nickname = request.getParameter("nickname");
		String sql = "update t_user set nick_name='"+nickname+"' where id="+user.getId();
		JdbcUtil.update(sql);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}